/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/2
 * \* Time: 13:01
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 树的子结构 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        return (A!=null&&B!=null)&&(recur(A,B)||isSubStructure(A.left,B)||isSubStructure(A.right,B));
    }

    boolean recur(TreeNode A,TreeNode B){
        if(B==null){
            return true;
        }

        if(A==null||A.val!=B.val){
            return false;
        }

        return recur(A.left,B.left)&&recur(A.right,B.right);
    }

}